

let counter = 0;
let nowFn = null;
export default class Reaction {
  store = {}
  constructor(){
    this.id = counter++;
  }
  collect(){
    if(nowFn){
      this.store[this.id] = this.store[this.id] || [];
      this.store[this.id].push(nowFn);
    }
  }
  run(){
     if(this.store[this.id].length){
       this.store[this.id].map(w=>{
         w()
       })
     }
  }
  static start(handler){
    nowFn = handler;
  }
  static end(){
    nowFn = null;
  }
}